package org.easy.control.controller;

import com.alibaba.fastjson.JSON;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.easy.common.domain.SysDictDO;
import org.easy.common.domain.SysDictDataDO;
import org.easy.common.domain.SysUserDO;
import org.easy.control.config.TestConfiguration;
import org.easy.module.service.TestService;
import org.easy.module.service.TestService1;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 周志鑫
 */
@Slf4j
@RequestMapping("/test")
@RestController
public class TestController {

    @Autowired
    TestService testService;
    @Autowired
    TestService1 testService1;
    @Autowired
    TestConfiguration configuration;

    @PostMapping("/testTransactional")
    public void testTransactional(@RequestBody SysDictDataDO sysDictDataDO) {
        testService.testTransactional(sysDictDataDO);
    }

    @GetMapping("/testParallelSearch")
    public void testParallelSearch() {
        testService.testParallelSearch1();
    }

    @GetMapping("/parallelTest")
    public void parallelTest() {
        new Thread(() -> testService.parallelTest(), "A").start();
        new Thread(() -> testService.parallelTest(), "B").start();
        new Thread(() -> testService.parallelTest(), "C").start();
    }

    @GetMapping("/testSqlInjection")
    public String testSqlInjection(@RequestParam(required = false) String userName) {
        SysUserDO userDO = testService.testSqlInjection(userName);
        return JSON.toJSONString(userDO);
    }

    @GetMapping("/testCache")
    public String testCache() {
        return testService.testCache();
    }

    @PostMapping("/testInsert")
    public void testInsert() {
        testService.testInsert();
    }

    @GetMapping("/testConfiguration")
    public void testConfiguration(){
        SysDictDO sysDictDO = configuration.test();
        System.out.println(sysDictDO);
    }

    @GetMapping("/testLimiting")
    public void testLimiting(){
        testService.testLimiting();
    }

}
